package com.efounder.utils;

import androidx.annotation.StringRes;

import com.efounder.thirdpartycomps.R;
import com.scwang.smartrefresh.layout.footer.ClassicsFooter;
import com.scwang.smartrefresh.layout.header.ClassicsHeader;
import com.utilcode.util.Utils;

/**
 * 从 Strng.xml 读取string
 *
 * @author YQS
 */
public class ResStringUtil {

    public static final String CAPTION = "caption";
    public static final String MULTI_LANGUAGE_KEY = "multiLanguageKey";

    /**
     * 获取string
     *
     * @param stringID
     * @return
     */
    public static String getString(@StringRes int stringID) {
        return Utils.getApp().getResources().getString(stringID);
    }

    /**
     * 通过字符串资源名的方式获取资源id
     *
     * @param clazz R.drawable.class
     * @param name  资源名 例ic_launcher_background
     * @return int
     */
    public static int getResIdByString(Class clazz, String name) {
        if (name == null) {
            return 0;
        }
        int resId = 0;
//        try {
//            Field field = clazz.getField(name);
//            resId = (Integer) field.get(clazz.newInstance());
//        } catch (NoSuchFieldException e) {
//            e.printStackTrace();
//        } catch (IllegalAccessException e) {
//            e.printStackTrace();
//        } catch (InstantiationException e) {
//            e.printStackTrace();
//        }

        try {
            resId = Utils.getApp().getResources().getIdentifier(name, "string", Utils.getApp().getPackageName());
        } catch (Exception e) {
            e.printStackTrace();
        }


        return resId;
    }

    /**
     * 初始化刷新控件文字提示
     */
    public static void initSmartRefreshLayoutHintText() {
        //"下拉可以刷新";
        ClassicsHeader.REFRESH_HEADER_PULLING = getString(R.string.srl_header_pulling);
        //"正在刷新...";
        ClassicsHeader.REFRESH_HEADER_REFRESHING = getString(R.string.srl_header_refreshing);
        //"正在加载...";
        ClassicsHeader.REFRESH_HEADER_LOADING = getString(R.string.srl_header_loading);
        //"释放立即刷新";
        ClassicsHeader.REFRESH_HEADER_RELEASE = getString(R.string.srl_header_release);
        //"刷新完成";
        ClassicsHeader.REFRESH_HEADER_FINISH = getString(R.string.srl_header_finish);
        //"刷新失败";
        ClassicsHeader.REFRESH_HEADER_FAILED = getString(R.string.srl_header_failed);
        //"上次更新 M-d HH:mm";
        ClassicsHeader.REFRESH_HEADER_UPDATE = getString(R.string.srl_header_update);

        //"上拉加载更多";
        ClassicsFooter.REFRESH_FOOTER_PULLING = getString(R.string.srl_footer_pulling);
        //"释放立即加载";
        ClassicsFooter.REFRESH_FOOTER_RELEASE = getString(R.string.srl_footer_release);
        //"正在刷新...";
        ClassicsFooter.REFRESH_FOOTER_REFRESHING = getString(R.string.srl_footer_refreshing);
        //"正在加载...";
        ClassicsFooter.REFRESH_FOOTER_LOADING = getString(R.string.srl_footer_loading);
        //"加载完成";
        ClassicsFooter.REFRESH_FOOTER_FINISH = getString(R.string.srl_footer_finish);
        //"加载失败";
        ClassicsFooter.REFRESH_FOOTER_FAILED = getString(R.string.srl_footer_failed);
        //"全部加载完成";
        ClassicsFooter.REFRESH_FOOTER_NOTHING = getString(R.string.srl_footer_nothing);
    }
}
